/* File: 0. run_all_cleaning.do
 * Author: Luca Maini
 * Purpose: runs all the .do files to clean the data
 *
 * Date Created: 07/30/2020
 *
 */

set more off
clear all
capture log close
set matsize 10000
set maxvar 10000


* Set directories 
* (EDIT THIS LINE TO MATCH YOUR HOME DIRECTORY WHEN WORKING WITH THIS FILE)
global db "E:\Dropbox (Personal)\Luca\Research\1. Active Projects\Master work with Josh\Pharmaceutical Mergers\submissions\JPE Micro\Final submission files\Replication folder"

global dodir "${db}\cleaning"
global logdir "${db}\logfiles"

global inputdir "${db}\data\input"
global outdir "${db}\data\output"
global maindir "${db}\data\main"


* open log file
log using "${logdir}\run_all_cleaning_${S_DATE}.txt", text replace

* Run all the scripts in the right order
do "${dodir}\1. cln_data.do"
do "${dodir}\2. cln_acquisition_data.do"
do "${dodir}\3. create_acquisition_variables.do"
do "${dodir}\4. make_formulary_data.do"
do "${dodir}\5. make_main_data.do"
do "${dodir}\6. add_extra_datasets.do"
do "${dodir}\7. create_matched_cohorts.do"
do "${dodir}\7b. create_matched_cohorts_noatc3.do"
do "${dodir}\8. build_matched_regression_datasets.do"
do "${dodir}\8b. build_matched_regression_datasets_noatc3.do"
do "${dodir}\9. einav_to_atc3.do"

clear all
capture log close

*** END CODE
